package com.demo.system.init.sentinel.fallback;

import com.alibaba.csp.sentinel.adapter.dubbo.fallback.DubboFallback;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.rpc.*;

import java.lang.reflect.Type;

/**
 * @author ：qilong sun
 * @date ：Created in 2020/8/14 15:18
 * @description：
 * @modified By：
 * @version: V1.0$
 */
@Slf4j
public class CustomerDefaultDubboFallback implements DubboFallback {
    @Override
    public Result handle(Invoker<?> invoker, Invocation invocation, BlockException e) {
        // 请求方法
        log.info("请求方法：{}", invocation.getMethodName());
        // 请求参数
        Object[] arguments = invocation.getArguments();
        log.info("请求参数：{}", JSONObject.toJSONString(arguments));
        // 获取出参
        RpcInvocation rpcInvocation = (RpcInvocation) invocation;
        Type[] returnTypes3 = rpcInvocation.getReturnTypes();
        String typeName = returnTypes3[0].getTypeName();
        log.info("出参类型：{}", typeName);
        return AsyncRpcResult.newDefaultAsyncResult("服务器处理不过来啦", invocation);
    }
}
